import Vue from 'vue'
import {getAction } from '@/api/manage'
import { getConfigBusinessList, getConfigOperatorList, getConfigSourceList } from '@/api/api'

export const BusinessMixin = {
  data () {
    return {
      produceList: []
    }
  },
  computed: {
  },
 
  created() {

  },
  methods: {
    getBusinessList(params) {
      let that = this;
      return new Promise(resolve => {
      getConfigBusinessList(params).then((res)=>{
        if(res) {
          // res.data.operatorList.forEach(item => {
            // item.value = item.name;
            // item.title = item.name;
          // })
          // that.materialTable.columns[0].options = res.data.operatorList
          that.typeList = res.data.operatorList
          resolve(res.data.operatorList)
        }
      })
      });
    },
    getSourceList(params) {
      let that = this;
      getConfigSourceList(params).then((res)=>{
        if(res) {
          that.sourceList = res.data.operatorList;
        }
      });
    },
    getOperatorList(params) {
      let that = this;
      getConfigOperatorList(params).then((res)=>{
        if(res) {
          res.data.operatorList.forEach(item => {
            item.value = item.name;
            item.title = item.name;
          })
          that.opeList = res.data.operatorList;
        }
      });
    },
     /** 查询某个tab的数据 */
     requestSubTableData(url, params, tab, success) {
      tab.loading = true
      getAction(url, params).then(res => {
        if(res && res.code === 200){

          let arr = res.data.name
          tab.dataSource = res.data.rows
          for(let item of this.materialTable.columns){
            if(item.key == 'produceId' ) {
              item.options = []
              for(let i=0; i<arr.length; i++) {
                let depotInfo = {};
                depotInfo.value = arr[i].produceId + '' //注意-此处value必须为字符串格式
                depotInfo.text = arr[i].produceName
                depotInfo.title = arr[i].produceName
                item.options.push(depotInfo)
              }
            }
          }
          typeof success === 'function' ? success(res) : ''
        }
      }).finally(() => {
        tab.loading = false
      })
    }
  }
}